home *** CD-ROM | disk | FTP | other *** search
- //***********************************************************************
- //
- // TextView.cpp
- //
- //***********************************************************************
-
- #include <afxwin.h>
- #include <afxext.h>
-
- #include "Resource.h"
- #include "CLine.h"
- #include "Paint6Doc.h"
- #include "TextView.h"
-
- IMPLEMENT_DYNCREATE (CTextView, CEditView)
-
- BEGIN_MESSAGE_MAP (CTextView, CEditView)
- ON_WM_CREATE ()
- END_MESSAGE_MAP ()
-
- BOOL CTextView::PreCreateWindow (CREATESTRUCT& cs)
- {
- if (!CEditView::PreCreateWindow (cs))
- return FALSE;
-
- cs.style |= ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL |
- ES_READONLY | WS_VSCROLL;
- return TRUE;
- }
-
- int CTextView::OnCreate (LPCREATESTRUCT lpcs)
- {
- if (CEditView::OnCreate (lpcs) == -1)
- return -1;
-
- CClientDC dc (this);
- int nHeight = -((dc.GetDeviceCaps (LOGPIXELSY) * 8) / 72);
-
- m_font.CreateFont (nHeight, 0, 0, 0, FW_NORMAL, 0, 0, 0,
- DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
- DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif");
-
- SetFont (&m_font, FALSE);
- return 0;
- }
-
- void CTextView::OnInitialUpdate ()
- {
- GetEditCtrl ().SetWindowText ("");
-
- CPaintDoc* pDoc = GetDocument ();
- int nCount = pDoc->GetLineCount ();
-
- if (nCount > 0) {
- for (int i=0; i<nCount; i++)
- AddEntry (pDoc->GetLine (i));
- }
- }
-
- void CTextView::OnUpdate (CView* pSender, LPARAM lHint, CObject* pHint)
- {
- if (pHint != NULL) {
- AddEntry ((CLine*) pHint);
- return;
- }
- CEditView::OnUpdate (pSender, lHint, pHint);
- }
-
- void CTextView::AddEntry (CLine* pLine)
- {
- int nLine = GetEditCtrl ().GetLineCount () - 1;
- int nIndex = GetEditCtrl ().LineIndex (nLine);
- GetEditCtrl ().SetSel (nIndex, nIndex);
-
- BOOL bDocState = GetDocument ()->IsModified ();
- GetEditCtrl ().ReplaceSel (pLine->GetDescription ());
- GetDocument ()->SetModifiedFlag (bDocState);
- }
-